package com.zuthub.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zuthub.common.annotation.Log;
import com.zuthub.common.core.controller.BaseController;
import com.zuthub.common.core.domain.AjaxResult;
import com.zuthub.common.enums.BusinessType;
import com.zuthub.system.domain.SysSponsorship;
import com.zuthub.system.service.ISysSponsorshipService;
import com.zuthub.common.utils.poi.ExcelUtil;
import com.zuthub.common.core.page.TableDataInfo;

/**
 * 赞助管理Controller
 * 
 * @author zuthub
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/system/sponsorship")
public class SysSponsorshipController extends BaseController
{
    @Autowired
    private ISysSponsorshipService sysSponsorshipService;

    /**
     * 查询赞助管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sponsorship:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSponsorship sysSponsorship)
    {
        startPage();
        List<SysSponsorship> list = sysSponsorshipService.selectSysSponsorshipList(sysSponsorship);
        return getDataTable(list);
    }

    @GetMapping("/tourist")
    @CrossOrigin
    public TableDataInfo listForTourist(SysSponsorship sysSponsorship)
    {
        startPage();
        List<SysSponsorship> list = sysSponsorshipService.selectSysSponsorshipList(sysSponsorship);
        return getDataTable(list);
    }

    /**
     * 导出赞助管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sponsorship:export')")
    @Log(title = "赞助管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysSponsorship sysSponsorship)
    {
        List<SysSponsorship> list = sysSponsorshipService.selectSysSponsorshipList(sysSponsorship);
        ExcelUtil<SysSponsorship> util = new ExcelUtil<SysSponsorship>(SysSponsorship.class);
        return util.exportExcel(list, "sponsorship");
    }

    /**
     * 获取赞助管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sponsorship:query')")
    @GetMapping(value = "/{sponsorshipId}")
    public AjaxResult getInfo(@PathVariable("sponsorshipId") Long sponsorshipId)
    {
        return AjaxResult.success(sysSponsorshipService.selectSysSponsorshipById(sponsorshipId));
    }

    /**
     * 新增赞助管理
     */
    @PreAuthorize("@ss.hasPermi('system:sponsorship:add')")
    @Log(title = "赞助管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSponsorship sysSponsorship)
    {
        return toAjax(sysSponsorshipService.insertSysSponsorship(sysSponsorship));
    }

    /**
     * 修改赞助管理
     */
    @PreAuthorize("@ss.hasPermi('system:sponsorship:edit')")
    @Log(title = "赞助管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSponsorship sysSponsorship)
    {
        return toAjax(sysSponsorshipService.updateSysSponsorship(sysSponsorship));
    }

    /**
     * 删除赞助管理
     */
    @PreAuthorize("@ss.hasPermi('system:sponsorship:remove')")
    @Log(title = "赞助管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sponsorshipIds}")
    public AjaxResult remove(@PathVariable Long[] sponsorshipIds)
    {
        return toAjax(sysSponsorshipService.deleteSysSponsorshipByIds(sponsorshipIds));
    }
}
